package org.netEase.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.netEase.dao.adverDao;
import org.netEase.entity.adver;
import org.netEase.util.BaseDao;

public class adverDaoImple extends BaseDao implements adverDao {

	@Override
	public List<adver> getall() {
		String sql ="select * from adver_table";
		List<adver> list = new ArrayList<>();
		ResultSet rs = super.executeQuery(sql);
		try {
			while(rs.next()) {
				adver adver = new adver();
				adver.setImid(rs.getInt("imid"));
				adver.setImg(rs.getString("img"));
				adver.setAdvertime(rs.getTimestamp("advertime"));
				adver.setState(rs.getString("state"));
				
				list.add(adver);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

	@Override
	public int add(adver ad) {
		  String sql = "insert into `adver_table` ( `img`, `state`) values (?, ?)";	
			return super.executeUpdate(sql, ad.getImg(),ad.getState());
	}

	@Override
	public int dele(int imid) {
		String sql = "delete from adver_table where imid = ?";
		return super.executeUpdate(sql, imid);
	}



}
